<?php 

function example(){
        $this->load->library('COM_excel');
        $xl_file="tmp/test.xls";
        $file_type="xls";
        $file_name="test";
        $excel = new COM_excel;
        $excel->newSheet('worksheting');
        /*header("Content-Type: application/$file_type");
        header("Content-Disposition: attachment; filename=$file_name");
        header("Pragma: no-cache");
        header("Expires: 0");
        */
        //Header
        $final_countries[1][0] = 'date';
        $final_countries[1][1] = 'name';
        $this->db->order_by('id','ASC');
        $qa=$this->db->get('activity');
        $qa=$qa->result_array();
        $j=2;
        foreach($qa as $q):
           $final_countries[1][$j] = $q['activity_type'];
           $j++;
        endforeach;
       /* Header */
        
        $this->db->select('*,activity_transaction.id');
        $this->db->join('customers','customers.id=activity_transaction.customer_id','LEFT');
		//$this->db->where('WEEK(activity_date)',date('w'));
        $this->db->groupby('activity_date');
        $this->db->groupby('customer_id');
        $q=$this->db->get('activity_transaction');
        $rows=$q->result_array();
        $i=2;
        foreach($rows as $row):
            $final_countries[$i][0] = $row['activity_date'];
            $final_countries[$i][1] = $row['customer_name'];
            $this->db->orderby('id','ASC');
            $qa=$this->db->get('activity');
            $qa=$qa->result_array();
            $j=2;
            foreach($qa as $q):
                /* Activity */
                $this->db->select('count(activity_id) as total');
                $this->db->where('activity_id',$q['id']);
                $this->db->where('id',$row['id']);
                $this->db->groupby('activity_id');
                $r=$this->db->get('activity_transaction');
                $r=$r->row_array();
                if(count($r)>0):
                    $total=$r['total'];
                else:
                    $total=0;
                endif;   
                $final_countries[$i][$j] = $total;
                $j++;
            endforeach;
            //$final_countries[$i][$j+1] = 3;
            $i++;
        endforeach;
        
        $excel->setChartData($final_countries);
        //$excel->setWidth(10);
        //$excel->removeCellBoundries();
        $excel->setChartType(COM_excel::xlLine);
        $excel->generateGraph("Zend Product by Geography");
        $excel->saveFile('C:\\test.xls');
        //redirect($excel->saveFile('./Countries.xls'));
        
    }
    
    function exceldealonemonth(){
        $excel = new COM_excel;
        $month=$this->input->post('month');
        $year =$this->input->post('year');
        
        /* Sheet 3 */
        $excel->newSheet('1 Tahun');
    
        $i=0;
        $j=0;
        $final3[$i][0]   =   "";
        $final3[$i+1][0] =   "";
        $final3[$i+2][0] =   month_name('01');
        $final3[$i+3][0] =   month_name('02');
        $final3[$i+4][0] =   month_name('03');
        $final3[$i+5][0] =   month_name('04');
        $final3[$i+6][0] =   month_name('05');
        $final3[$i+7][0] =   month_name('06');
        $final3[$i+8][0] =   month_name('07');
        $final3[$i+9][0] =   month_name('08');
        $final3[$i+10][0]=   month_name('09');
        $final3[$i+11][0]=   month_name('10');
        $final3[$i+12][0]=   month_name('11');
        $final3[$i+13][0]=   month_name('12');
        
        $deal  =  $this->reports->getDealYearly($year); 
        $i=0;
        $j=0;
        foreach($deal as $row):
            $final3[$i+1][$j+1] = $row['username'];
            $final3[$i+2][$j+2] = $row['month_1'];
            $final3[$i+3][$j+3] = $row['month_2'];
            $final3[$i+4][$j+4] = $row['month_3'];
            $final3[$i+5][$j+5] = $row['month_4'];
            $final3[$i+6][$j+6] = $row['month_5'];
            $final3[$i+7][$j+7] = $row['month_6'];
            $final3[$i+8][$j+8] = $row['month_7'];
            $final3[$i+9][$j+9] = $row['month_8'];
            $final3[$i+10][$j+10] = $row['month_9'];
            $final3[$i+11][$j+11] = $row['month_10'];
            $final3[$i+12][$j+12] = $row['month_11'];
            $final3[$i+13][$j+13] = $row['month_12'];
            $j++;
        endforeach;
        $excel->setChartData($final3);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,900,300);
        $excel->generateGraph("Deal","User List","Total",2,1); 
        /* Sheet 3 */
        
        /* Sheet 2 */
        $excel->newSheet('3 Bulan');
        if(($month=='01') || ($month=='02') || ($month=='03')):
            $month_1  = '01';
            $month_2  = '02';
            $month_3  = '03';
        elseif(($month=='04') || ($month=='05') || ($month=='06')):    
            $month_1  = '04';
            $month_2  = '05';
            $month_3  = '06';
        elseif(($month=='07') || ($month=='08') || ($month=='09')):    
            $month_1  = '07';
            $month_2  = '08';
            $month_3  = '09';
        elseif(($month=='10') || ($month=='11') || ($month=='12')):    
            $month_1  = '10';
            $month_2  = '11';
            $month_3  = '12';         
        endif;
        
        $i=0;
        $j=0;
        $final2[$i][0]   =   "";
        $final2[$i+1][0] =   "";
        $final2[$i+2][0] =   month_name($month_1);
        $final2[$i+3][0] =   month_name($month_2);
        $final2[$i+4][0] =   month_name($month_3);
        $deal  =  $this->reports->getDealMonthly($month_1,$month_2,$month_3,$year); 
        $i=0;
        $j=0;
        foreach($deal as $row):
            $final2[$i+1][$j+1] = $row['username'];
            $final2[$i+2][$j+2] = $row['month_1'];
            $final2[$i+3][$j+3] = $row['month_2'];
            $final2[$i+4][$j+4] = $row['month_3'];
            $j++;
        endforeach;
        $excel->setChartData($final2);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,600,200);
        $excel->generateGraph("Deal","User List","Total",2,1); 
        /* Sheet 2 */
        
        /* Sheet 1 */
        $excel->newSheet('Bulan '.$month.','.$year);
        $i=0;
        $j=0;
        $final[$i][0]   =   "";
        $final[$i+1][0] =   "";
        $final[$i+2][0] =   "Rev";
        $final[$i+3][0] =   "Target";
        $deal  =  $this->reports->getDeal($month,$year); 
        $i=0;
        $j=0;
        foreach($deal as $row):
            $final[$i+1][$j+1] = $row['username'];
            $final[$i+2][$j+2] = $row['total'];
            $final[$i+3][$j+3] = $row['target'];
            $j++;
        endforeach;
        $excel->setChartData($final);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,400,200);
        $excel->generateGraph("Deal","User List","Total",2,1); 
        /* Sheet 1 */
        
        
        $excel->saveFile('C:\\deal.xls');
        redirect($this->config->item('report'));
    }
    
    function excelrealonemonth(){
        $excel = new COM_excel;
        $month=$this->input->post('month');
        $year =$this->input->post('year');
        
        /* Sheet 3 */
        $excel->newSheet('1 Tahun');
    
        $i=0;
        $j=0;
        $final3[$i][0]   =   "";
        $final3[$i+1][0] =   "";
        $final3[$i+2][0] =   month_name('01');
        $final3[$i+3][0] =   month_name('02');
        $final3[$i+4][0] =   month_name('03');
        $final3[$i+5][0] =   month_name('04');
        $final3[$i+6][0] =   month_name('05');
        $final3[$i+7][0] =   month_name('06');
        $final3[$i+8][0] =   month_name('07');
        $final3[$i+9][0] =   month_name('08');
        $final3[$i+10][0]=   month_name('09');
        $final3[$i+11][0]=   month_name('10');
        $final3[$i+12][0]=   month_name('11');
        $final3[$i+13][0]=   month_name('12');
        
        $deal  =  $this->reports->getRealYearly($year); 
        $i=0;
        $j=0;
        foreach($deal as $row):
            $final3[$i+1][$j+1] = $row['username'];
            $final3[$i+2][$j+2] = $row['month_1'];
            $final3[$i+3][$j+3] = $row['month_2'];
            $final3[$i+4][$j+4] = $row['month_3'];
            $final3[$i+5][$j+5] = $row['month_4'];
            $final3[$i+6][$j+6] = $row['month_5'];
            $final3[$i+7][$j+7] = $row['month_6'];
            $final3[$i+8][$j+8] = $row['month_7'];
            $final3[$i+9][$j+9] = $row['month_8'];
            $final3[$i+10][$j+10] = $row['month_9'];
            $final3[$i+11][$j+11] = $row['month_10'];
            $final3[$i+12][$j+12] = $row['month_11'];
            $final3[$i+13][$j+13] = $row['month_12'];
            $j++;
        endforeach;
        $excel->setChartData($final3);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,900,300);
        $excel->generateGraph("Realisasi","User List","Total",2,1); 
        /* Sheet 3 */
        
        /* Sheet 2 */
        $excel->newSheet('3 Bulan');
        if(($month=='01') || ($month=='02') || ($month=='03')):
            $month_1  = '01';
            $month_2  = '02';
            $month_3  = '03';
        elseif(($month=='04') || ($month=='05') || ($month=='06')):    
            $month_1  = '04';
            $month_2  = '05';
            $month_3  = '06';
        elseif(($month=='07') || ($month=='08') || ($month=='09')):    
            $month_1  = '07';
            $month_2  = '08';
            $month_3  = '09';
        elseif(($month=='10') || ($month=='11') || ($month=='12')):    
            $month_1  = '10';
            $month_2  = '11';
            $month_3  = '12';         
        endif;
        
        $i=0;
        $j=0;
        $final2[$i][0]   =   "";
        $final2[$i+1][0] =   "";
        $final2[$i+2][0] =   month_name($month_1);
        $final2[$i+3][0] =   month_name($month_2);
        $final2[$i+4][0] =   month_name($month_3);
        $deal  =  $this->reports->getRealMonthly($month_1,$month_2,$month_3,$year); 
        $i=0;
        $j=0;
        foreach($deal as $row):
            $final2[$i+1][$j+1] = $row['username'];
            $final2[$i+2][$j+2] = $row['month_1'];
            $final2[$i+3][$j+3] = $row['month_2'];
            $final2[$i+4][$j+4] = $row['month_3'];
            $j++;
        endforeach;
        $excel->setChartData($final2);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,600,200);
        $excel->generateGraph("Realisasi","User List","Total",2,1); 
        /* Sheet 2 */
        
        /* Sheet 1 */
        $excel->newSheet('Bulan '.$month.','.$year);
        $i=0;
        $j=0;
        $final[$i][0]   =   "";
        $final[$i+1][0] =   "";
        $final[$i+2][0] =   "Rev";
        $final[$i+3][0] =   "Target";
        $deal  =  $this->reports->getReal($month,$year); 
        $i=0;
        $j=0;
        foreach($deal as $row):
            $final[$i+1][$j+1] = $row['username'];
            $final[$i+2][$j+2] = $row['total'];
            $final[$i+3][$j+3] = $row['target'];
            $j++;
        endforeach;
        $excel->setChartData($final);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,400,200);
        $excel->generateGraph("Realisasi","User List","Total",2,1); 
        /* Sheet 1 */
        
        
        $excel->saveFile('C:\\Realisasi.xls');
        redirect($this->config->item('report'));
    }
    
    function exceltypeonemonth(){
        $excel = new COM_excel;
        $month=$this->input->post('month');
        $year =$this->input->post('year');
    
        /* Sheet 1 */
        $excel->newSheet('Bulan '.$month.','.$year);
        $i=0;
        $j=0;
        $final[$i][0]   =   "";
        $final[$i+1][0] =   "";
        $final[$i+1][1] =   "Repeat";
        $final[$i+1][2] =   "First";
        $deal  =  $this->reports->getType($month,$year); 
        $i=1;
        $j=0;
        $repeat=0;
        $first=0;
        foreach($deal as $row):
            $final[$i+1][$j]   = $row['username'];
            $final[$i+1][$j+1] = $row['repeat_'];
            $repeat=$repeat+$row['repeat_'];
            $final[$i+1][$j+2] = $row['first_'];
            $first=$first+$row['first_'];
            $i++;
        endforeach;
        $excel->setChartData($final);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,400,200);
        $excel->generateGraph("Repeat - First","User List","Total",2,2); 
        /* Sheet 1 */
        
        /* Sheet 2 */
        $excel->newSheet('Total '.$month.','.$year);
        $i=0;
        $j=0;
        $final2[$i][0]   =   "";
        $final2[$i+1][0] =   "";
        $final2[$i+1][1] =   "Repeat";
        $final2[$i+1][2] =   "First";
        //$deal  =  $this->reports->getType($month,$year); 
        $i=1;
        $j=0;
         //foreach($deal as $row):
            $final2[$i+1][$j]   = "Total";
            $final2[$i+1][$j+1] = $repeat;
            $final2[$i+1][$j+2] = $first;
            //$i++;
        //endforeach;
        $excel->setChartData($final2);
        $excel->setChartType(COM_excel::xlPie,400,0,400,200);
        $excel->generateGraph("Repeat-First"); 
        /* Sheet 2 */
        $excel->saveFile('C:\\First-Repeat.xls');
        redirect($this->config->item('report'));
    }
    
    function excelincomingonemonth(){
        $excel = new COM_excel;
        $month=$this->input->post('month');
        $year =$this->input->post('year');
    
        /* Sheet 1 */
        $excel->newSheet('Bulan '.$month.','.$year);
        $i=0;
        $j=0;
        $final[$i][0]   =   "";
        $final[$i+1][0] =   "";
        $final[$i+1][1] =   "Incoming";
        $final[$i+1][2] =   "Non Incoming";
        $deal  =  $this->reports->getIncoming($month,$year); 
        $i=1;
        $j=0;
        $in=0;
        $non=0;
        foreach($deal as $row):
            $final[$i+1][$j]   = $row['username'];
            $final[$i+1][$j+1] = $row['in_'];
            $in=$in+$row['in_'];
            $final[$i+1][$j+2] = $row['non_'];
            $non=$non+$row['non_'];
            $i++;
        endforeach;
        $excel->setChartData($final);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,400,200);
        $excel->generateGraph("Incoming - Non","User List","Total",2,2); 
        /* Sheet 1 */
        
        /* Sheet 2 */
        $excel->newSheet('Total '.$month.','.$year);
        $i=0;
        $j=0;
        $final2[$i][0]   =   "";
        $final2[$i+1][0] =   "";
        $final2[$i+1][1] =   "Incoming";
        $final2[$i+1][2] =   "Non Incoming";
        //$deal  =  $this->reports->getType($month,$year); 
        $i=1;
        $j=0;
         //foreach($deal as $row):
            $final2[$i+1][$j]   = "Total";
            $final2[$i+1][$j+1] = $in;
            $final2[$i+1][$j+2] = $non;
            //$i++;
        //endforeach;
        $excel->setChartData($final2);
        $excel->setChartType(COM_excel::xlPie,400,0,400,200);
        $excel->generateGraph("Incoming - Non Incoming"); 
        /* Sheet 2 */
        $excel->saveFile('C:\\Incoming-Non_Incoming.xls');
        redirect($this->config->item('report'));
    }
    
    function excelproductonemonth(){
        $excel = new COM_excel;
        $month=$this->input->post('month');
        $year =$this->input->post('year');

        /* Sheet 1 */
        $excel->newSheet('Bulan '.$month.','.$year);
        
        $deal  =  $this->reports->getUserp(); 
        $i=0;
        $j=0;
        $final[$i][0]   =   "";
        $final[$i+1][0] =   "";
        foreach($deal as $row):
            $final[$i+1][$j+1] = $row['username'];
            $j++;
        endforeach;
        
        $i=0;
        $j=0;
        $final[$i][0]   =   "";
        $final[$i+1][0] =   "";
        $prod=$this->reports->getProducts();
        foreach($prod as $rec):
            $final[$i+2][0] =   $rec['product_name'].'-'.$rec['product_time'];
            $user=$this->reports->getUserp(); 
            $j=1;
            foreach($user as $row):
                $jobs = $this->reports->getJobProducts($row['username'],$rec['id'],$month,$year);
                if(count($jobs)>=1):
                    $total=$jobs['total'];
                else:
                    $total=0;
                endif;
                        
                $final[$i+2][$j+1] = $total ;
                $j++;
            endforeach;
            $i++;
        endforeach;
        
        $excel->setChartData($final);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,400,200);
        $excel->generateGraph("Product List","User List","Total",2,2); 
        /* Sheet 1 */
        
        
        /* Sheet 2 */
        $excel->newSheet('Total '.$month.','.$year);
        
        //$deal  =  $this->reports->getUserp(); 
        //$i=0;
        //$j=0;
        //$final[$i][0]   =   "";
        //$final[$i+1][0] =   "";
        //foreach($deal as $row):
        //    $final[$i+1][$j+1] = $row['username'];
        //    $j++;
        //endforeach;
        
        $i=0;
        $j=0;
        $final2[$i][0]   =   "";
        $final2[$i+1][0] =   "";
        $prod=$this->reports->getProducts();
        foreach($prod as $rec):
            $final2[$i+2][0] =   $rec['product_name'].'-'.$rec['product_time'];
            $user=$this->reports->getUserp(); 
            $j=1;
            //foreach($user as $row):
                $jobs = $this->reports->getJobProductTotal($rec['id'],$month,$year);
                if(count($jobs)>=1):
                    $total=$jobs['total'];
                else:
                    $total=0;
                endif;      
                $final2[$i+2][$j+1] = $total ;
                //$j++;
            //endforeach;
            $i++;
        endforeach;
        
        $excel->setChartData($final2);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,400,200);
        $excel->generateGraph("Product List","User List","Total",2,2); 
        /* Sheet 2 */
        
        
        $excel->saveFile('C:\\products.xls');
        redirect($this->config->item('report'));
    }
    
    function excelsectoronemonth(){
        $excel = new COM_excel;
        $month=$this->input->post('month');
        $year =$this->input->post('year');

        /* Sheet 1 */
        $excel->newSheet('Bulan '.$month.','.$year);
        
        $deal  =  $this->reports->getUserp(); 
        $i=0;
        $j=0;
        $final[$i][0]   =   "";
        $final[$i+1][0] =   "";
        foreach($deal as $row):
            $final[$i+1][$j+1] = $row['username'];
            $j++;
        endforeach;
        
        $i=0;
        $j=0;
        $final[$i][0]   =   "";
        $final[$i+1][0] =   "";
        $sec=$this->reports->getSectors();
        foreach($sec as $rec):
            $final[$i+2][0] =   $rec['sector_name'];
            $user=$this->reports->getUserp(); 
            $j=1;
            foreach($user as $row):
                $jobs = $this->reports->getJobSectors($row['username'],$rec['id'],$month,$year);
                if(count($jobs)>=1):
                    $total=$jobs['total'];
                else:
                    $total=0;
                endif;
                        
                $final[$i+2][$j+1] = $total ;
                $j++;
            endforeach;
            $i++;
        endforeach;
        
        $excel->setChartData($final);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,400,200);
        $excel->generateGraph("Sector List","User List","Total",2,2); 
        /* Sheet 1 */
        
        
        /* Sheet 2 */
        $excel->newSheet('Total '.$month.','.$year);
        
        //$deal  =  $this->reports->getUserp(); 
        //$i=0;
        //$j=0;
        //$final[$i][0]   =   "";
        //$final[$i+1][0] =   "";
        //foreach($deal as $row):
        //    $final[$i+1][$j+1] = $row['username'];
        //    $j++;
        //endforeach;
        
        $i=0;
        $j=0;
        $final2[$i][0]   =   "";
        $final2[$i+1][0] =   "";
        $sec=$this->reports->getSectors();
        foreach($sec as $rec):
            $final2[$i+2][0] =   $rec['sector_name'];
            //$user=$this->reports->getUserp(); 
            $j=1;
            //foreach($user as $row):
                $jobs = $this->reports->getJobSectorTotal($rec['id'],$month,$year);
                if(count($jobs)>=1):
                    $total=$jobs['total'];
                else:
                    $total=0;
                endif;
                        
                $final2[$i+2][$j+1] = $total ;
                //$j++;
            //endforeach;
            $i++;
        endforeach;
        
        $excel->setChartData($final2);
        $excel->setChartType(COM_excel::xlColumnClustered,400,0,400,200);
        $excel->generateGraph("Sector List","User List","Total",2,2); 
        /* Sheet 2 */
        
        
        $excel->saveFile('C:\\sector.xls');
        redirect($this->config->item('report'));
    }
    
    
    function exceldealmonth(){ 
        set_time_limit(3360);   
        $objPHPExcel = new PHPExcel();
        $fill = array(
      			'type'       => Style_Fill::FILL_SOLID,
      			'rotation'   => 0,
      			'startcolor' => array(
      				'rgb' => 'CCCCCC'
      			),
      			'endcolor'   => array(
      				'argb' => 'CCCCCC'
      			)
  		);  
        
        $objPHPExcel->createSheet();
        $objPHPExcel->setActiveSheetIndex(0);
        $this->charting->chartdeal("PHP|Java",'chart');
        $objPHPExcel->getActiveSheet()->setTitle('Bulan'.month_name($this->input->post('month')));
        $styleArray = array( 'borders' => array( 'allborders' => array(
                             'style' => Style_Border::BORDER_THIN )));
                         
		/*Data */
		$row=1;
		$col=1;
		$deal = $this->reports->getDeal($this->input->post('month'),$this->input->post('year'));
        foreach($deal as $rec):
		/* User ID */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$rec['username']);
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+1,$rec['total']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+2,$rec['target']);
        $col++;
		/* User ID */
        endforeach;
        
        $row=2;
		$col=0;
        
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Rev');
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+1,'Target');
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+1)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+1)->getFill()->applyFromArray($fill);
        
        $objDrawing = new Worksheet_Drawing();
        $objDrawing->setName('Example Chart');
        $objDrawing->setDescription('Example Chart');
        $objDrawing->setPath('chart.png');
        $objDrawing->setCoordinates('H6');
        $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
        
        //new sheet
        $objPHPExcel->createSheet();
        $objPHPExcel->setActiveSheetIndex(1);
        if(($this->input->post('month')=='01') || ($this->input->post('month')=='02') || ($this->input->post('month')=='03') ):
            $month1='01';
            $month2='02';
            $month3='03';
        elseif(($this->input->post('month')=='04') || ($this->input->post('month')=='05') || ($this->input->post('month')=='06')):    
            $month1='04';
            $month2='05';
            $month3='06';
        elseif(($this->input->post('month')=='07') || ($this->input->post('month')=='08') || ($this->input->post('month')=='09')):    
            $month1='07';
            $month2='08';
            $month3='09';
        elseif(($this->input->post('month')=='10') || ($this->input->post('month')=='11') || ($this->input->post('month')=='12')):    
            $month1='10';
            $month2='11';
            $month3='12';         
        endif;
        
        $this->charting->chart3deal("PHP|Java",'chart3',$month1,$month2,$month3);
        $objPHPExcel->getActiveSheet()->setTitle('Per 3 Bulan');
        /*Data */
		$row=1;
		$col=1;
        
		$month = $this->reports->getDealMonthly($month1,$month2,$month3,$this->input->post('year'));
        foreach($month as $rec):
		/* User ID */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$rec['username']);
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+1,$rec['month_1']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+2,$rec['month_2']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+3,$rec['month_3']);
        $col++;
		/* User ID */
        endforeach;
        
        $row=2;
		$col=0;
        
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,month_name($month1));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+1,month_name($month2));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+1)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+1)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+2,month_name($month3));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+2)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+2)->getFill()->applyFromArray($fill);
        
        
        $objDrawing = new Worksheet_Drawing();
        $objDrawing->setName('Example Chart');
        $objDrawing->setDescription('Example Chart');
        $objDrawing->setPath('chart3.png');
        $objDrawing->setCoordinates('H6');
        $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
        
        //new sheet 1 year
        $objPHPExcel->createSheet();
        $objPHPExcel->setActiveSheetIndex(2);
        $this->charting->chart12deal("Deal Project 12",'chart12');
        $objPHPExcel->getActiveSheet()->setTitle('Per 12 Bulan');
        /*Data */
		$row=1;
		$col=1;
        
		$year = $this->reports->getDealYearly($this->input->post('year'));
        foreach($year as $rec):
		/* User ID */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$rec['username']);
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+1,$rec['month_1']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+2,$rec['month_2']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+3,$rec['month_3']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+4,$rec['month_4']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+5,$rec['month_5']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+6,$rec['month_6']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+7,$rec['month_7']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+8,$rec['month_8']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+9,$rec['month_9']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+10,$rec['month_10']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+11,$rec['month_11']);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+12,$rec['month_12']);
        
        $col++;
		/* User ID */
        endforeach;
        
        $row=2;
		$col=0;
        
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,month_name('01'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+1,month_name('02'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+1)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+1)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+2,month_name('03'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+2)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+2)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+3,month_name('04'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+3)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+3)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+4,month_name('05'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+4)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+4)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+5,month_name('06'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+5)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+5)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+6,month_name('07'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+6)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+6)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+7,month_name('08'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+7)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+7)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+8,month_name('09'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+8)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+8)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+9,month_name('10'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+9)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+9)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+10,month_name('11'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+10)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+10)->getFill()->applyFromArray($fill);
        
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row+11,month_name('12'));
		$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+11)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row+11)->getFill()->applyFromArray($fill);
        
        
        $objDrawing = new Worksheet_Drawing();
        $objDrawing->setName('Example Chart');
        $objDrawing->setDescription('Example Chart');
        $objDrawing->setPath('chart12.png');
        $objDrawing->setCoordinates('H6');
        $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
        
        
        $objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");
		$file="deal_list.xls";
		$objWriter->save('crm-media/data/deal/'.$file);
		redirect('crm-media/data/deal/'.$file,301);	

    }